package component;

import general.*;
import vector.Vector2;

public final class BoxCollider extends Component
{
	public Vector2 offset;
	public Vector2 area;
	public int layerMask;
	public int targetLayerMask;
	
	public BoxCollider(Vector2 _offset,Vector2 _area,int _layerMask,int _targetLayerMask)
	{
		enabled = true;
		offset = _offset;
		area =_area;
		layerMask = _layerMask;
		targetLayerMask =_targetLayerMask;
	}
	
	public Rect getRect()
	{
		Vector2 pos = gameObject.getPosition().add(offset);
		return new Rect(pos.x,pos.y,pos.x+area.x,pos.y+area.y);
	}
	
	public boolean Collide(BoxCollider bc)
	{
		if((bc.layerMask & targetLayerMask)!= 0)
			return getRect().InterSect(bc.getRect());
		return false;
	}
}
